package com.ruoyi.web.controller.pc.uc;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.page.PageUtils;
import com.ruoyi.web.domain.*;
import com.ruoyi.web.domain.vo.QueryVo;
import com.ruoyi.web.domain.vo.UcFeedbackVo;
import com.ruoyi.web.domain.wx.AppQueryVo;
import com.ruoyi.web.service.IUcFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/userConfig/feedback")
public class UcFeedbackController extends BaseController {

    @Autowired
    private IUcFeedbackService ucFeedbackService;


    @PreAuthorize("@ss.hasPermi('userConfig:feedback:list')")
    @GetMapping("/list")
    public TableDataInfo list(QueryVo queryVo) {
        PageUtils page = ucFeedbackService.listByPage(queryVo);
        return getDataTable(page);
    }

    @PreAuthorize("@ss.hasPermi('userConfig:feedback:remove')")
    @Log(title = "意见反馈删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable("id") List<Long> ids){
        return toAjax(ucFeedbackService.delete(ids));
    }


    @PreAuthorize("@ss.hasPermi('userConfig:feedback:reply')")
    @PostMapping("/reply")
    public AjaxResult reply(@RequestBody UcFeedbackVo ucFeedback) {
        ucFeedbackService.reply(ucFeedback);
        return toAjax(1);
    }

    /**
     * 反馈意见
     */
    @Log(title = "反馈意见", businessType = BusinessType.INSERT)
    @PostMapping("/feedback")
    public AjaxResult feedback(@RequestBody UcFeedback ucFeedback){
        try {
            ucFeedbackService.insert(ucFeedback);
            return success();
        } catch (Exception e) {
            return error("反馈意见异常，请联系管理员:"+e.getMessage());
        }
    }

    @PostMapping("/getFeedbackListByUser")
    public TableDataInfo getFeedbackListByUser(@RequestBody AppQueryVo appQueryVo) {

        if(appQueryVo.getQUserId() == null){
            appQueryVo.setQUserId(SecurityUtils.getUserId());
        }
        appQueryVo.setIsAsc("ascending");
        appQueryVo.setOrderByColumn("id");
        PageUtils page = ucFeedbackService.appListByPage(appQueryVo);
        return getDataTable(page);

    }

}

